{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a1c0efd5",
   "metadata": {},
   "source": [
    "## 购物车程序项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c672de4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的支付宝余额:900\n",
      "------goods list------\n",
      "编号:0, 商品名称: iphone8,商品价格: 5400 元\n",
      "编号:1, 商品名称: clothes,商品价格: 250 元\n",
      "编号:2, 商品名称: flowers,商品价格: 150 元\n",
      "编号:3, 商品名称: food,商品价格: 300 元\n",
      "编号:4, 商品名称: cosmetics,商品价格: 450 元\n",
      "编号:5, 商品名称: python课本,商品价格: 234 元\n",
      "请输入购买商品的编号:9\n",
      "您选择的商品不存在\n",
      "------goods list------\n",
      "编号:0, 商品名称: iphone8,商品价格: 5400 元\n",
      "编号:1, 商品名称: clothes,商品价格: 250 元\n",
      "编号:2, 商品名称: flowers,商品价格: 150 元\n",
      "编号:3, 商品名称: food,商品价格: 300 元\n",
      "编号:4, 商品名称: cosmetics,商品价格: 450 元\n",
      "编号:5, 商品名称: python课本,商品价格: 234 元\n"
     ]
    }
   ],
   "source": [
    "goods_list = [(\"iphone8\",5400),\n",
    "             (\"clothes\",250),\n",
    "             (\"flowers\",150),\n",
    "             (\"food\",300),\n",
    "             (\"cosmetics\",450),\n",
    "             (\"python课本\",234),\n",
    "             ]\n",
    "shopping_list = []\n",
    "Alipay = int(input(\"请输入你的支付宝余额:\"))\n",
    "while True:\n",
    "    print(\"------goods list------\")\n",
    "    for i in range(len(goods_list)):\n",
    "        print(\"编号:%s, 商品名称: %s,商品价格: %s 元\"%(i,goods_list[i][0],goods_list[i][1]))\n",
    "    choice = input(\"请输入购买商品的编号:\")\n",
    "    if choice.isdigit():\n",
    "        choice = int(choice)\n",
    "        if choice > len(goods_list):\n",
    "            print(\"您选择的商品不存在\")\n",
    "        else:\n",
    "            if Alipay > goods_list[choice][1]:\n",
    "                shopping_list.append(goods_list[choice])\n",
    "                Alipay = Alipay - goods_list[choice][1]\n",
    "                print(\"【%s】已加入您的购物车，您的余额账户还有： %s 元\"%(goods_list[choice][0],Alipay))\n",
    "            else:\n",
    "                print(\"你的余额不足\")\n",
    "    elif choice == \"q\":\n",
    "        print(\"用户购物车：\",shopping_list)\n",
    "        print(\"您的余额还有：\",Alipay)\n",
    "        break\n",
    "    else:\n",
    "        print(\"请输入商品编号：\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cc1f963d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "05a2886e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "273.188px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "position": {
    "height": "22px",
    "left": "1268px",
    "right": "20px",
    "top": "120px",
    "width": "78px"
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
